<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>汇报列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header table-operate-btn">
							<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='alladd'>添加</button>
						</div>
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">状态：</label>
									<div class="layui-input-inline">
										<select name="status" class="work_order_status"></select>
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">优先级：</label>
									<div class="layui-input-inline">
										<select name="level" class="work_order_level"></select>
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">订单号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="订单号" name="orderid" autocomplete="off">
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">项目名称\编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="名称\编号" name="pkeywords" autocomplete="off">
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员名称\编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="名称\编号" name="mkeywords" autocomplete="off">
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">用户名称\编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="名称\编号" name="ukeywords" autocomplete="off">
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">时间：</label>
									<div class="layui-input-inline">
										<input class="layui-input" id="choosetime" placeholder="时间" name="report_date" autocomplete="off">
										<input class="layui-input" type="hidden" name="s_dates" placeholder="" autocomplete="off">
										<input class="layui-input" type="hidden" name="e_dates" placeholder="" autocomplete="off">
									</div>
								</div>

								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->

							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="test-table-operate-barDemo">
								<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
								<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">查看</a>
								{{# if(d.status == 2 ){ }}
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="success">结单</a>
								{{# } }}
							</script>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					admin = layui.admin;

				map_show({
					mapName: 'work_order_level',
					domType: 'option',
					fieldName: 'status'
				})
				map_show({
					mapName: 'work_order_status',
					domType: 'option',
					fieldName: 'type'
				})
				var _data = {}
				initdata();

				function initdata() {
					table.render({
						elem: '#test-table-operate',
						url: wd_server.erp_work_order_myinsert,
						height: height_155,
						cellMinWidth: cellMinWidth,
						limit: limit,
						limits: limits,
						cols: [
							[{
								width: 60,
								type: 'numbers',
								title: '序号',
								fixed: 'left',
							}, {
								width: 190,
								align: 'center',
								toolbar: '#test-table-operate-barDemo',
								title: '操作',
								fixed: 'left',
							}, {
								field: 'orderid',
								width: 120,
								title: '订单编号'
							}, {
								field: 'status',
								title: '状态',
								width: 120,
								templet: function(d) {
									return String(d.status) ? map_show({
										mapName: 'work_order_status',
										data: d.status
									}) : ''
								}
							}, {
								field: 'level',
								title: '优先级',
								width: 120,
								templet: function(d) {
									return String(d.level) ? map_show({
										mapName: 'work_order_level',
										data: d.level
									}) : ''
								}
							}, {
								field: '',
								width: 160,
								title: '会员',
								templet: function(d) {
									return(d.membername ? d.membername : '') + "(" + (d.memberid ? d.memberid : '') + ")"
								}
							}, {
								field: '',
								width: 160,
								title: '用户',
								templet: function(d) {
									return(d.username ? d.username : '') + "(" + (d.userid ? d.userid : '') + ")"
								}
							}, {
								field: '',
								width: 160,
								title: '项目',
								templet: function(d) {
									return(d.project_name ? d.project_name : '') + "(" + (d.project_id ? d.project_id : '') + ")"
								}
							}, {
								field: '',
								width: 160,
								title: '应用',
								templet: function(d) {
									return(d.app_name ? d.app_name : '') + "(" + (d.app_id ? d.app_id : '') + ")"
								}
							}, {
								field: 'hours',
								width: 80,
								title: '工时',
								templet: function(d) {
									return d.hours ? d.hours + "(小时)" : ''
								}
							}, {
								field: 'fee',
								width: 80,
								title: '费用',
							}, {
								field: 'problem_desc',
								width: 260,
								title: '问题描述',
							}, {
								field: '',
								width: 160,
								title: '负责人',
								templet: function(d) {
									return d.persons_name ? (d.persons_name ? d.persons_name : '') + "(" + (d.persons_id ? d.persons_id : '') + ")" : ''
								}
							}, {
								field: 'scheduled_time',
								width: 180,
								title: '预计完成时间',
							}, {
								field: 'notes',
								width: 180,
								title: '备注',
							}, {
								field: 'addtime',
								width: 180,
								title: '创建时间',
							}]
						],
						page: true,
						where: _data,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.erp_work_order.pager.total, //解析数据长度
								"data": res.erp_work_order.data //解析数据列表
							};
						}
					});
				}

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if(!value) {
							return '姓名不能为空';
						}
					}
				});

				//日期时间范围
				laydate.render({
					elem: '#choosetime',
					// type: 'datetime',
					range: true,
					done: function(value, date) {
						$('input[name=s_dates]').val(value.split(' - ')[0]);
						$('input[name=e_dates]').val(value.split(' - ')[1]);
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field
					initdata();
					return false;
				});
				$("button[type=reset]").on("click", function() {
					_data = {}
					initdata();
					document.getElementById("form").reset();
				});
				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});

				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'edit') {
						layer.open({
							type: 2,
							title: '修改',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['80%', '90%'],
							content: 'edit_add.html?id=' + data.id,
							end: function() {},
							success: function() {

							}
						});
					} else if(obj.event === 'detail') {
						layer.open({
							type: 2,
							title: '修改',
							shadeClose: false,
							shade: 0.5,
							maxmin: true, //开启最大化最小化按钮
							area: ['80%', '90%'],
							content: '../model/detail.html?id=' + data.id + '&orderid=' + data.orderid,
							end: function() {},
							success: function() {

							}
						});
					} else if(obj.event === 'success') {
						layer.confirm('您是确定要完成结单吗？', function() {
							$.ajax({
							url: wd_server.erp_work_order_sub_success,
							type: 'post',
							dataType: 'json',
							data: "orderid=" + data.orderid,
							success: function(data) {
								if(data.code == '0') {
									layer.msg('操作成功');
									initdata()
								} else {
									layer.msg('操作失败');
								}
							},
							'error': function() {
								layer.msg('系统错误');
							}
						})}, function() {
							layer.msg('取消操作');
						});
					}
				});

				//删除
				$('#del').on('click', function() {
					var checkStatus = table.checkStatus('test-table-operate'),
						data = JSON.stringify(checkStatus.data);
					var id = "";
					for(var i = 0; i < checkStatus.data.length; i++) {
						id += checkStatus.data[i].id;
						if(i != checkStatus.data.length - 1) {
							id += ",";
						}
					}
					layer.confirm('确定要删除所选的' + checkStatus.data.length + '条数据？', function() {
						$.ajax({
							url: wd_server.customer_delete,
							type: 'post',
							dataType: 'json',
							data: "id=" + id,
							success: function(data) {
								if(data.code == '0') {
									layer.msg('删除成功');
									initdata()
								} else {
									layer.msg('删除失败');
								}
							},
							'error': function() {
								layer.msg('系统错误');
							}
						})
					});
				});

				var $ = layui.$,
					active = {
						alladd: function() {
							layer.open({
								type: 2,
								title: '添加',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['80%', '90%'],
								content: 'edit_add.html?',
								end: function() {},
								success: function() {}
							});
						},
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

			});
		</script>
	</body>

</html>